package com.xq.shop.controller;


import com.xq.shop.dto.EditRestCalendarDto;
import com.xq.shop.dto.IntegerDto;
import com.xq.shop.dto.QueryDto;
import com.xq.shop.service.IRestCalendarService;
import com.xq.shop.service.IUserService;
import com.xq.shop.vo.NoticeVo;
import com.xq.shop.vo.RestCalendarVo;
import com.xq.shop.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import utils.BasePage;
import utils.BaseResult;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 休息日历表 前端控制器
 * </p>
 *
 * @author gaoxiaojin
 * @since 2024-07-19
 */
@RestController
@RequestMapping("/rest/calendar")
public class RestCalendarController {

    private final IUserService userService;
    private final IRestCalendarService restCalendarService;

    @Autowired
    public RestCalendarController(IUserService userService, IRestCalendarService restCalendarService) {
        this.userService = userService;
        this.restCalendarService = restCalendarService;
    }

    @RequestMapping("/page")
    public BaseResult<BasePage<RestCalendarVo>> page(@RequestBody QueryDto dto, HttpServletRequest request) {
        userService.getInfo(request);
        BaseResult<BasePage<RestCalendarVo>> result = new BaseResult<>();
        BasePage<RestCalendarVo> page = restCalendarService.pageQuery(dto);
        result.initializeSuccess(page);
        return result;
    }

    @RequestMapping("/edit")
    public BaseResult<Void> edit(@RequestBody @Validated EditRestCalendarDto dto, HttpServletRequest request) {
        UserVo userVo = userService.getInfo(request);
        BaseResult<Void> result = new BaseResult<>();
        restCalendarService.edit(dto, userVo.getId());
        result.initializeSuccess();
        return result;
    }

    @RequestMapping("/remove")
    public BaseResult<Void> remove(@RequestBody @Validated IntegerDto dto, HttpServletRequest request) {
        UserVo userVo = userService.getInfo(request);
        BaseResult<Void> result = new BaseResult<>();
        restCalendarService.removeRestCalendar(dto, userVo.getId());
        result.initializeSuccess();
        return result;
    }

    @RequestMapping("/regular")
    public BaseResult<RestCalendarVo> regular() {
        BaseResult<RestCalendarVo> result = new BaseResult<>();
        result.initializeSuccess(restCalendarService.getRegular());
        return result;
    }

}
